//
//  IndexGridView.m
//  linlee-iotios
//
//  Created by mengze on 2025/5/25.
//

#import <Masonry/Masonry.h>
#import "IndexGridView.h"
#import "UIColor+Hex.h"

@interface IndexGridView()

@end

@implementation IndexGridView

- (instancetype)init {
    self = [super init];
    if (self) {
        [self setupUI];
    }
    return self;
}

- ( void ) setStatus: (int) status {
    //表示正常
    if( status == 0 ){
        [self.statusLabel setBackgroundColor:[UIColor successColor]];
        [self.detailLabel setText:@"正常"];
        [self.switchControl setOn:true];
        return;
    }
    [self.statusLabel setBackgroundColor:[UIColor warnColor]];
    [self.detailLabel setText:@"故障"];
    [self.switchControl setOn:false];
    
}
 
- (void)setupUI {
    self.layer.cornerRadius = 10;
    self.layer.borderWidth = 1;
    self.layer.borderColor = [UIColor colorWithHexString:@"D3E2D0"].CGColor;
    
    _imageView = [[UIImageView alloc] init];
    _imageView.contentMode = UIViewContentModeScaleAspectFit;
    _imageView.backgroundColor = [UIColor lightGrayColor];
    
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.font = [UIFont systemFontOfSize:14];
    [_titleLabel setTextColor:[UIColor colorWithHexString:@"383F37"]];
    
    
    _statusLabel = [[UILabel alloc] init];
    _statusLabel.layer.cornerRadius = 3;
    _statusLabel.layer.masksToBounds = YES;
    
    _detailLabel = [[UILabel alloc] init];
    _detailLabel.font = [UIFont systemFontOfSize:12];
    _detailLabel.textColor = [UIColor colorWithHexString:@"ACB1AB"];
    _detailLabel.numberOfLines = 0;
    
    _switchControl = [[UISwitch alloc] init];
    
    [self addSubview:_imageView];
    [self addSubview:_titleLabel];
    [self addSubview:_statusLabel];
    [self addSubview:_detailLabel];
    [self addSubview:_switchControl];
    

    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self).offset(10);
//        make.top.equalTo(_imageView);
//        make.left.equalTo(_imageView.mas_right).offset(10);
//        make.right.equalTo(self).offset(-10);
    }];
    
    [_statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLabel.mas_bottom).offset(10);
        make.left.equalTo(_titleLabel);
        make.width.height.equalTo(@(6));
    }];
    
    [_detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLabel.mas_bottom).offset(5);
        make.left.equalTo(_statusLabel.mas_right).offset(4);
    }];
    
    
    [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(10);
        make.top.equalTo( self.detailLabel.mas_bottom ).offset(20);
        make.width.height.mas_equalTo(40);
    }];
    
    [_switchControl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.titleLabel).offset(5);
        make.right.equalTo(self).offset(-10);
    }];
}
@end
